﻿using System;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TfsCommitMonitor.Tests
{
	[TestClass]
	public class ConfigurationTest
	{
		[ClassInitialize()]
		public static void MyClassInitialize(TestContext testContext)
		{
			var isolatedConfigFileName = typeof(Configuration).GetField("_isolatedConfigFileName", BindingFlags.NonPublic | BindingFlags.Static);
			isolatedConfigFileName.SetValue(null, String.Format("unitTest_{0}", Configuration.IsolatedConfigFileName));
		}
	

		[TestMethod]
		public void PersistToDiskTest()
		{
			var generator = new Random();
			Configuration.Instance.MaxChangesToPersist = generator.Next(10, 100);
			Configuration.Instance.MaxNumberOfChangesetsOnInitialLoad = generator.Next(10, 100);
			Configuration.Instance.PersistToDisk();

			var clonedInstance = Configuration.Instance.Clone();

			var privateInstance = typeof(Configuration).GetField("_instance", BindingFlags.NonPublic | BindingFlags.Static);
			privateInstance.SetValue(null, null);
			Assert.IsNull(privateInstance.GetValue(null));


			Assert.AreEqual(clonedInstance, Configuration.Instance);
		}
	}
}
